@echo off
echo === 完整监控流程测试 ===
echo 使用注册IP: 198.18.0.1
echo.

echo 🔧 第一步：注册Agent
echo 发送注册请求...
curl -X POST "http://all.roywise.cn:8081/api/deviceMonitor/agent/register" ^
     -H "Content-Type: application/json" ^
     -d "{\"hostname\":\"DESKTOP-TEST\",\"ipAddress\":\"198.18.0.1\",\"osType\":\"windows\",\"osVersion\":\"windows-10\",\"agentVersion\":\"1.0.0\"}" ^
     -o register_response.json

echo.
echo 注册响应:
type register_response.json
echo.

echo 解析AgentID...
for /f "tokens=2 delims=:" %%a in ('findstr "agentId" register_response.json') do (
    set "agent_id_raw=%%a"
)

:: 清理AgentID，移除引号和逗号
set agent_id=%agent_id_raw:"=%
set agent_id=%agent_id:,=%
set agent_id=%agent_id: =%

echo Agent ID: %agent_id%
echo.

echo 💓 第二步：发送心跳
curl -X POST "http://all.roywise.cn:8081/api/deviceMonitor/agent/heartbeat" ^
     -H "Content-Type: application/json" ^
     -d "{\"agentId\":\"%agent_id%\",\"status\":\"ONLINE\",\"timestamp\":%time%}" ^
     -o heartbeat_response.json

echo 心跳响应:
type heartbeat_response.json
echo.

echo 📋 第三步：获取监控配置
curl -X GET "http://all.roywise.cn:8081/api/deviceMonitor/agent/config/%agent_id%" ^
     -H "Content-Type: application/json" ^
     -o config_response.json

echo 监控配置响应:
type config_response.json
echo.

echo ✅ API流程测试完成！
pause